<template>
  <div id="labItemDict">
    <Breadcrumb content="项目维护" v-if="showBreadCrumbTag === true" />
    <GoBack :content="'项目维护'" v-if="showBreadCrumbTag === false" @closeDrawer="closeDrawer" :backUrl="url"></GoBack>
    <div class="bodyContent">
      <Splitpanes>
        <Pane :size="50">
          <vxe-form :data="searchForm" class="searchform form-input-m">

            <vxe-form-item title="报告单元">
              <template #default>
                <SelectWorkGroupAll ref="selectWorkGroupRef" :url="'/api/rptGroup/findPoctRptGroup'" :inputWidth="'100%'" @fatherMethod="searchWklt" :isShowAll="true" :isClear="true"></SelectWorkGroupAll>
              </template>
            </vxe-form-item>
            <vxe-form-item title="项目归类">
              <vxe-select v-model="searchForm.itemClass" :filterable="true" @change="getReportItemList" clearable>
                <vxe-option v-for="item in itemClassDict" :key="item.code" :label="item.name" :value="item.code"></vxe-option>
              </vxe-select>
            </vxe-form-item>
            <vxe-form-item title="仪器大类">
              <vxe-select v-model="searchForm.instrClass" :filterable="true" @change="getReportItemList" clearable>
                <vxe-option v-for="item in instrClassDict" :key="item.code" :label="item.name" :value="item.code"></vxe-option>
              </vxe-select>
            </vxe-form-item>

            <vxe-form-item title="快速查询">
              <vxe-input v-model="searchForm.searchValue" placeholder="请输入" clearable @keyup="keyupEnter" />
            </vxe-form-item>
            <vxe-form-item>
              <el-radio-group v-model="searchForm.enable">
                <el-radio :label="1">启用</el-radio>
                <el-radio :label="0">禁用</el-radio>
              </el-radio-group>
            </vxe-form-item>
            <vxe-form-item>
              <el-button size="small" type="primary" @click="getReportItemList">查询</el-button>
              <el-button size="small" type="success" @click="handleAdd" :disabled="!searchForm.rptGroup">新建</el-button>
              <el-button size="small" type="danger" @click="handleDelete">删除</el-button>
              <vxe-button type="text" class="button-blue" icon="vxe-icon-caret-up" content="上移" @click="moveUp()" :disabled="sltItemIndex == 0"></vxe-button>
              <vxe-button type="text" class="button-blue" icon="vxe-icon-caret-down" content="下移" @click="moveDown()" :disabled="itemList.length == 0 || sltItemIndex == (itemList.length - 1)"></vxe-button>
              <vxe-button type="text" class="button-blue" icon="vxe-icon-sort" content="数据同步" :loading="loadingSync" @click="pullPloyee"></vxe-button>
              <vxe-button type="text" class="button-blue" icon="vxe-icon-sort" content="项目知识库同步" :loading="showKnowLedgeLoading" @click="pullItemDictKnowLedge"></vxe-button>
            </vxe-form-item>
            <vxe-form-item title-width="250" title=" ">
              <vxe-button type="text" class="button-blue" icon="vxe-icon-sort" content="从标准库创建" :disabled="!searchForm.rptGroup" @click="staSync"></vxe-button>
            </vxe-form-item>

          </vxe-form>
          <div class="tablecenter" :style="{ height: tableBodyHeight }">
            <vxe-table ref="reportTable" class="mytable-scrollbar" border="inner" :scroll-y="{ enabled: true }" resizable show-header-overflow show-overflow height="auto" align="left" :row-config="{ isCurrent: true, isHover: true }" @current-change="rowClick" :data="itemList" :loading="showLoading">
              <vxe-column type="checkbox" width="30px"></vxe-column>
              <vxe-column field="seq" title="项目序号" width="80"></vxe-column>
              <vxe-column field="itemNo" title="项目代码" width="80"></vxe-column>
              <vxe-column field="itemNa" title="项目名称" min-width="140"></vxe-column>
              <vxe-column field="itemEnCode" title="缩写" width="100"></vxe-column>
              <vxe-column field="unit" title="单位" width="60"></vxe-column>
              <vxe-column field="itemKind" title="结果类型" width="80">
                <template #default="{ row }">
                  <span>{{ formatCommon(itemKindDict, row.itemKind) }}</span>
                </template>
              </vxe-column>
              <vxe-column field="itemClass" title="项目归类" width="60">
                <template #default="{ row }">
                  <span>{{ formatCommon(itemClassDict, row.itemClass) }}</span>
                </template>
              </vxe-column>
              <vxe-column field="instrClass" title="仪器大类" width="60">
                <template #default="{ row }">
                  <span>{{ formatCommon(instrClassDict, row.instrClass) }}</span>
                </template>
              </vxe-column>
              <vxe-column field="rptGroup" title="报告单元" width="150">
                <template #default="{ row }">
                  <span>{{ formatReportGroup(reportGroupDict, row.rptGroup) }}</span>
                </template>
              </vxe-column>
            </vxe-table>
          </div>
        </Pane>

        <Pane :size="50">
          <el-tabs type="border-card" v-model="activeName">
            <el-tab-pane label="基本信息" class="tab-content-wrapper" name="infoTab">
              <LabItemDictInfoPoct ref="labItemDictInfoRef" :formProp="form" :rptGroup="searchForm.rptGroup" :itemClassDict="itemClassDict" :instrClassDict="instrClassDict" :reportGroupDict="reportGroupDict" :itemKindDict="itemKindDict" @editOrAddLabItemDict='editOrAddLabItemDict' v-loading="showLoading" element-loading-text="Loading..." v-if="isinit" />
              <LabItemDictInfoPoct v-else />
            </el-tab-pane>
            <el-tab-pane label="参考范围" class="tab-content-wrapper" name="refeTab" :disabled="isDisabled">
              <LabItemDictInfoRefer ref="refRowData" />
            </el-tab-pane>
            <el-tab-pane label="危急值" class="tab-content-wrapper" name="criticalTab" :disabled="isDisabled">
              <LabItemDictInfoCritical ref="refRowCriticalData" />
            </el-tab-pane>
            <el-tab-pane label="文字结果" class="tab-content-wrapper" name="resultsTab" :disabled="isDisabled">
              <TextResults ref="textResultsRef" />
            </el-tab-pane>
            <el-tab-pane label="通道号" class="tab-content-wrapper" name="channelTab" :disabled="isDisabled">
              <LabChannel ref="refChannelData" />
            </el-tab-pane>
            <el-tab-pane label="结果二次处理" class="tab-content-wrapper" name="transTab" :disabled="isDisabled">
              <TransResult ref="transResultRef" />
            </el-tab-pane>
            <el-tab-pane label="合并关系维护" class="tab-content-wrapper" name="merger" :disabled="isDisabled">
              <MergerRelationship ref="mergerRelationshipRef" />
            </el-tab-pane>
            <ExtraPropertyPanel :busRow="form" />
          </el-tabs>
        </Pane>
      </Splitpanes>
      <el-drawer title="报告项目标准库创建" v-model="showMenuDialog" size="50%">
          <el-tabs type="border-card" v-model="staSyncName">
            <el-tab-pane label="检验项目" class="tab-content-wrapper" name="feeItem" style="height:950px;">
              <vxe-toolbar perfect>
                <template #buttons>
                  <vxe-select v-model="searchMenuForm.workGroup" :filterable="true" @change="staSyncGetData" clearable>
                    <vxe-option v-for="item in workGroupList" :key="item.code" :label="item.name" :value="item.code"></vxe-option>
                  </vxe-select>
                  <vxe-button type="text" class="button-blue" content="复制" @click="saveBacthByFeeItem()"></vxe-button>
                </template>
              </vxe-toolbar>
              <vxe-table :span-method="mergeRowMethod" ref="staFeeDictTableRef"  border height="95%" align="center"
                         :data="feeItemList" :loading="lloading" :column-config="{ resizable: true }" resizable show-overflow keep-source>
                <vxe-column field="feeName" title="检验项目" width="90"></vxe-column>
                <vxe-column type="checkbox" width="30"></vxe-column>
                <vxe-column type="seq" title="#" width="30"></vxe-column>
                <vxe-column field="itemNo" title="报告项目代号"></vxe-column>
                <vxe-column field="itemNa" title="报告项目名称"></vxe-column>
              </vxe-table>
            </el-tab-pane>
            <el-tab-pane label="报告项目" class="tab-content-wrapper" name="dictItem" style="height:950px;">
              <vxe-toolbar perfect>
                <template #buttons>
                  <vxe-select v-model="searchMenuForm.workGroup" :filterable="true" @change="staSyncGetData" clearable>
                    <vxe-option v-for="item in workGroupList" :key="item.code" :label="item.name" :value="item.code"></vxe-option>
                  </vxe-select>
                  <vxe-button type="text" class="button-blue" content="复制" @click="saveBacthByDictItem()"></vxe-button>
                </template>
              </vxe-toolbar>
              <vxe-table  ref="dictItemTabRef"  border height="95%" align="center"
                          :data="dictItemList" :loading="lloading" :row-config="{ keyField: 'id', isHover: true }"
                          :column-config="{ resizable: true }" resizable show-overflow keep-source>

                <vxe-column type="checkbox" width="30"></vxe-column>
                <vxe-column type="seq" title="#" width="30"></vxe-column>
                <vxe-column field="itemNo" title="报告项目代号"></vxe-column>
                <vxe-column field="itemNa" title="报告项目名称"></vxe-column>
              </vxe-table>
            </el-tab-pane>
          </el-tabs>


      </el-drawer>

    </div>
  </div>

</template>
<script setup lang="ts">
// 引入组件区 ==========
import Breadcrumb from '@/components/Breadcrumb.vue'; //面包屑
import GoBack from '@/components/GoBack.vue'; //返回组件
import LabItemDictInfoRefer from '@/views/lab_sys/lab_set/LabItemDictInfoRefer.vue';
import LabItemDictInfoCritical from '@/views/lab_sys/lab_set/LabItemDictInfoCritical.vue';
import { ref, reactive, getCurrentInstance, onMounted, computed } from 'vue';
import { IsEmpty, sortByField } from '@/utils/common';
import { Splitpanes, Pane } from 'splitpanes';
import { VxeTablePropTypes } from 'vxe-table';
import { VXETable } from 'vxe-table';
import XEUtils from 'xe-utils';
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage';
import LabItemDictInfoPoct from './LabItemDictInfoPoct.vue';
import TransResult from '@/views/lab_sys/lab_set/TransResult.vue';
import MergerRelationship from '@/views/lab_sys/lab_set/MergerRelationship.vue';
import TextResults from '@/views/lab_sys/lab_set/TextResults.vue';
import LabChannel from '@/views/lab_sys/lab_set/LabChannel.vue';
import ExtraPropertyPanel from '@/components/ExtraPropertyPanel.vue';
import { assign } from 'lodash';
import { AppStore } from '@/stores/store';
import { isEmpty } from 'lodash';
import { LocPost } from '@/utils/LocRequestHelper';
import SelectWorkGroupAll from '@/views/lab_sys/lab_bus/components/SelectWorkGroupAll.vue'; //报告单元默认全部引入下拉组件
import { GetRptGroupOptions } from '@/utils/SysOptionsHelper';
import Axios from '@/api';

// 全局变量定义区 ==========
let { proxy }: any = getCurrentInstance();
let store = AppStore();

let useSize = ref(localStorage.getItem('uiSize') || 'small'); //当前选择的三个尺寸
const tableBodyHeight = computed(() => {
  if (useSize.value === 'default') {
    return 'calc(100% - 106px)';
  } else if (useSize.value === 'large') {
    return 'calc(100% - 114px)';
  } else {
    return 'calc(100% - 104px)';
  }
});

let activeName = ref('infoTab');
let staSyncName = ref('feeItem');
const orgList = store.userInfo.orgList;
// 最左侧表单
let searchForm = reactive({
  itemClass: '',
  instrClass: '',
  rptGroup: '',
  workGroup: '',
  workGroupName: '',
  searchValue: '',
  enable: 1,
  poct: 1,
  orgId: store.userInfo.orgId,
  orgName: store.userInfo.orgName
});
let defaultProps = {
  children: 'children',
  label: 'name'
};
const labItemDictInfoRef = ref(null); /** */
const itemClassDict = reactive([]); //项目类型字典
const instrClassDict = reactive([]); //仪器大类字典
const reportGroupDict = reactive([]); //报告单元字典
const itemKindDict = reactive([]); //结果类型字典
const feeItemList = reactive([]); //结果类型字典
const dictItemList = reactive([]); //结果类型字典
let showLoading = ref(false); //表格加载状态
let showMenuDialog = ref(false); //表格加载状态
let lloading = ref(false); //弹框表格数据加载状态
let itemList: any = reactive([]); //表格数据
let workGroupList: any = reactive([]); //字典表：指控规则类型
let sltPurpose: any = ref({});
let sltItemIndex: any = ref();

let showKnowLedgeLoading = ref(false);

let isinit = ref(false); //右侧基本信息 if初始化组件
let form: any = reactive({}); //右侧基本信息表单
let transResultRef: any = ref(null); //结果二次处理传值
let mergerRelationshipRef: any = ref(null); //合并关系传值
let textResultsRef: any = ref(null); //文字结果传值
let loadingSync = ref(false); //同步数据加载中
let isDisabled = ref(true);
let dictTreeTypeCodes: any = reactive(['reportCategory', 'YQDL', 'LABITEMKIND', 'JYGZZ']);
let refRowData: any = ref(null); //报告项目当前行
let refRowCriticalData: any = ref(null); //报告项目危急值
let channelData = {
  rptGroup: '',
  itemDictRow: ref(null)
};
let refChannelData: any = ref(null); //传值给通道号

let searchMenuForm = reactive({
  seachValue: '',
  workGroup:''
});

// 方法定义区 =============
defineExpose({
  init
});

let showBreadCrumbTag = ref(true); //当为true时显示的是普通面包屑 false显示的是返回组件
let url = ref(''); //抽屉要返回的路由地址

function init(row: any, row2: any) {
  url.value = row;
  showBreadCrumbTag.value = !row2;
}

// 关闭抽屉
function closeDrawer() {
  showBreadCrumbTag.value = true; //恢复成面包屑
  proxy.$emit('closeDrawer');
}

onMounted(async () => {
  getDictItemsList(); //批量获取字典 包含了(项目归类/仪器大类)
  getReportGroupDict(); //获取报告单元字典
});

//获取报告单元字典
function getReportGroupDict() {
  reportGroupDict.length = 0;
  const url = '/api/rptGroup/findPoctRptGroup';
  proxy.$http
    //注意此处的数据条数
    .get(url)
    .then((res: any) => {
      reportGroupDict.push(...res.data);
    })
    .catch((err: any) => {
      // VxeMessage('获取获取当前字典的字段列表失败',VxeNotifyType.error)
    });
}

//批量获取字典
async function getDictItemsList() {
  const codes = dictTreeTypeCodes.join(',');
  const url = '/api/sys/basDictDetail/findDictDetailListByDictCodes';
  const dictTreeTypeItems: any = await proxy.$http.get(url, { params: { code: codes } });
  let itemClassType = dictTreeTypeItems.data.find((item) => item.code === 'JYGZZ');
  itemClassDict.push(...itemClassType.detailDataList);
  //searchForm.itemClass = itemClassDict[0].code;

  const instrClassType = dictTreeTypeItems.data.find((item) => item.code === 'YQDL');
  instrClassDict.push(...instrClassType.detailDataList);
  //searchForm.instrClass = instrClassDict[0].code;

  const itemKindType = dictTreeTypeItems.data.find((item) => item.code === 'LABITEMKIND');
  itemKindDict.push(...itemKindType.detailDataList);

  const jygzzType = dictTreeTypeItems.data.find((item) => item.code === 'JYGZZ');
  workGroupList.push(...jygzzType.detailDataList);
}

// 表格 项目归类/仪器大类/结果类型 格式化
function formatCommon(arr, value) {
  for (const item of arr) {
    if (item.code == value) {
      return item.name;
    }
  }
}

// 表格 报告单元 格式化
function formatReportGroup(arr, value) {
  for (const item of arr) {
    if (item.rptGroup == value) {
      return item.rptGroupName;
    }
  }
}

// 回车查询
function keyupEnter(e: any) {
  if (e.$event.code == 'Enter') {
    getReportItemList();
  }
}

// 表格点击当前行
const rowClick = ({ row, rowIndex }) => {
  isinit.value = false;
  const $reportTable = proxy.$refs.reportTable;
  if ($reportTable) {
    $reportTable.setCurrentRow(row);
    if (isEmpty(row.rptGroup)) {
      isDisabled.value = true;
    } else {
      isDisabled.value = false;
    }
    proxy.$nextTick(() => {
      setTimeout(() => {
        $reportTable.scrollToRow(row);
      }, 150);
    });
  }
  Object.assign(form, row);
  //根据ID获取当前报告单元
  sltPurpose.value = row;
  sltItemIndex.value = rowIndex;
  channelData.rptGroup = row.rptGroup;
  channelData.itemDictRow.value = row;
  refRowData.value.initPage(row); //传递给右侧基本信息表单
  refRowCriticalData.value.criticalData(row); //传递给右侧基本信息表单
  transResultRef.value.initTransResult(row);
  mergerRelationshipRef.value.initMergerRelationship(row);
  textResultsRef.value.initTextResult(row);
  refChannelData.value.ChannelInitPage(channelData);
  labItemDictInfoRef.value?.initPage({ rptGroup: form.rptGroup, formProp: form });
  setTimeout(() => {
    isinit.value = true;
  }, 50);
};

function editOrAddLabItemDict(rowId: any) {
  sltPurpose.value.id = rowId;
  findLabItemDictList();
}

function getReportItemList() {
  sltPurpose.value.id = null;
  sltItemIndex.value = 0;
  findLabItemDictList();
}

// 获取申请项目列表
function findLabItemDictList() {
  itemList.length = 0;
  showLoading.value = true;
  const url = '/lis/lab/item/findLabItemDictList';
  proxy.$http
    .get(url, { params: searchForm })
    .then((res: any) => {
      itemList.length = 0;
      res.data.forEach((eItm) => {
        if (!IsEmpty(eItm.decPos)) {
          eItm.decPos = parseInt(eItm.decPos, 10);
          eItm.decPos = eItm.decPos < 0 ? 0 : eItm.decPos;
        }
      });
      itemList.push(...res.data);
      if (itemList.length > 0) {
        const kn = itemList.find((k) => k.id == sltPurpose.value.id);
        const knindex = itemList.findIndex((k) => k.id == sltPurpose.value.id);
        if (isEmpty(kn)) {
          rowClick({ row: itemList[0], rowIndex: 0 }); //默认选中第一条数据
        } else {
          rowClick({ row: kn, rowIndex: knindex }); //默认选中第一条数据
        }
      }
      channelData.rptGroup = searchForm.rptGroup;
      showLoading.value = false;
    })
    .catch((err: any) => {
      proxy.$alert(err, '提示');
      showLoading.value = false;
    });
}

// 新建
function handleAdd() {
  isinit.value = false;
  // form = { id: '' };
  form = reactive({});
  isDisabled.value = true;

  form.rptGroup = searchForm.rptGroup;
  form.decPos = 2;
  form.poct = 1;
  form.itemKind = '4';
  if (itemList.length > 0) {
    form.seq = itemList[itemList.length - 1].seq + 10;
  } else {
    form.seq = 10;
  }
  if (!isEmpty(searchForm.instrClass)) {
    form.instrClass = searchForm.instrClass;
  } else {
    form.instrClass = sltPurpose.value.instrClass;
  }
  if (!isEmpty(searchForm.itemClass)) {
    form.itemClass = searchForm.itemClass;
  } else {
    form.itemClass = sltPurpose.value.itemClass;
  }

  form.enable = 1;
  sltPurpose.value = {};
  (proxy.$refs.reportTable as any).clearCurrentRow();
  activeName.value = 'infoTab';

  setTimeout(() => {
    isinit.value = true;
  }, 500);
}

// 删除数据
function handleDelete() {
  const selectRows = (proxy.$refs.reportTable as any).getCheckboxRecords();
  if (selectRows.length > 1) {
    VxeMessage('一次只可选择删除一条数据', VxeNotifyType.warning);
    return;
  }
  if (selectRows.length <= 0) {
    VxeMessage('请选择需要删除的项目', VxeNotifyType.warning);
    return;
  }
  const url = '/lis/lab/item/deleteLabItemDict';
  proxy.$http
    .post(url, selectRows[0])
    .then((res: any) => {
      getReportItemList();
      VxeMessage(res.status.msg, VxeNotifyType.success);
    })
    .catch((err: any) => {
      VxeMessage(err, VxeNotifyType.error);
    });
}
//标准同步
async function staSync() {
  showMenuDialog.value=true;
  staSyncGetData();
}

//选中保存
function saveBacthByFeeItem() {
  if (isEmpty(searchForm.workGroup)|| isEmpty(searchForm.rptGroup)){
    VxeMessage('请选择报告单元', VxeNotifyType.warning);
  }
//后端查询塞入
  const selectRows = (proxy.$refs.staFeeDictTableRef as any).getCheckboxRecords();
  if (selectRows.length <= 0) {
    VxeMessage('请选择需要同步的数据', VxeNotifyType.warning);
    return;
  }
  const data={
    workGroup:searchForm.workGroup,
    rptGroup:searchForm.rptGroup,
    staItemDicts:selectRows
  }
  const url = '/lis/lab/item/batchSaveDictItem';
  proxy.$http
      .post(url, data)
      .then((res: any) => {
        if (res.status.code == 1){
          closeMenuDialog();
          getReportItemList();
          VxeMessage(res.status.msg, VxeNotifyType.success);
        }else {
          VxeMessage(res.status.msg, VxeNotifyType.error);
        }
      })
      .catch((err: any) => {
        VxeMessage(err, VxeNotifyType.error);
      });
}
//选中保存
function saveBacthByDictItem() {
  if (isEmpty(searchForm.workGroup)|| isEmpty(searchForm.rptGroup)){
    VxeMessage('请选择报告单元', VxeNotifyType.warning);
  }
//后端查询塞入
  const selectRows = (proxy.$refs.dictItemTabRef as any).getCheckboxRecords();
  if (selectRows.length <= 0) {
    VxeMessage('请选择需要同步的数据', VxeNotifyType.warning);
    return;
  }
  const data={
    workGroup:searchForm.workGroup,
    rptGroup:searchForm.rptGroup,
    staItemDicts:selectRows
  }
  const url = '/lis/lab/item/batchSaveDictItem';
  proxy.$http
      .post(url, data)
      .then((res: any) => {
        if (res.status.code == 1){
          closeMenuDialog();
          getReportItemList();
          VxeMessage(res.status.msg, VxeNotifyType.success);
        }else {
          VxeMessage(res.status.msg, VxeNotifyType.error);
        }
      })
      .catch((err: any) => {
        VxeMessage(err, VxeNotifyType.error);
      });
}

// 弹框取消按钮
function closeMenuDialog() {
  searchMenuForm.seachValue = '';
  showMenuDialog.value = false;
}

//从标准库创建查询方法
function staSyncGetData() {
  findDictDataByFeeList();
  getDictData();
}

//检验项目获取报告项目
function findDictDataByFeeList() {
  if (isEmpty(searchMenuForm.workGroup)){
    VxeMessage('请选择工作组', VxeNotifyType.warning);
    return;
  }
  lloading.value = true;
  feeItemList.length = 0; //放入数据前清空数据
  const url = '/lis/sta/feeItem/findDictByFeeList';
  proxy.$http
      //注意此处的数据条数
      .get(url, {
        params: {
          seachValue: searchMenuForm.seachValue,
          workGroup: searchMenuForm.workGroup,
          rptGroup:  searchForm.rptGroup
        }
      })
      .then((res: any) => {
        feeItemList.push(...res.data);
        lloading.value = false;
      })
      .catch((err: any) => {
        lloading.value = false;
        VxeMessage('获取获取弹框表格数据异常', VxeNotifyType.error);
      });
}
//报告项目
function getDictData() {

  if (isEmpty(searchMenuForm.workGroup)){
    VxeMessage('请选择工作组', VxeNotifyType.warning);
    return;
  }
  lloading.value = true;
  dictItemList.length = 0; //放入数据前清空数据
  const url = '/lis/sta/staItemDict/findStaItemDictList';
  proxy.$http
      //注意此处的数据条数
      .get(url, {
        params: {
          seachValue: searchMenuForm.seachValue,
          workGroup: searchMenuForm.workGroup,
          rptGroup:  searchForm.rptGroup
        }
      })
      .then((res: any) => {
        dictItemList.push(...res.data);
        lloading.value = false;
      })
      .catch((err: any) => {
        lloading.value = false;
        VxeMessage('获取获取弹框表格数据异常', VxeNotifyType.error);
      });
}


function mergeRowMethod({ row, _rowIndex, column, visibleData }) {
  const fields = ['feeName']
  const cellValue = row[column.field]
  if (cellValue && fields.includes(column.field)) {
    const prevRow = visibleData[_rowIndex - 1]
    let nextRow = visibleData[_rowIndex + 1]
    if (prevRow && prevRow[column.field] === cellValue) {
      return { rowspan: 0, colspan: 0 }
    } else {
      let countRowspan = 1
      while (nextRow && nextRow[column.field] === cellValue) {
        nextRow = visibleData[++countRowspan + _rowIndex]
      }
      if (countRowspan > 1) {
        return { rowspan: countRowspan, colspan: 1 }
      }
    }
  }
}

// 同步数据
async function pullPloyee() {
  loadingSync.value = true;
  const url = '/lis/lab/item/syncItemDicts';
  const params = {
    url: (window as any).apiUrl.VUE_APP_INTERFACE_URL + '/lisInterface/lisInterfacePost',
    code: 'GET_EMPLOYEE'
  };
  proxy.$http
    .get(url, { params: params })
    .then((res: any) => {
      loadingSync.value = false;
      findPloyeeList();
    })
    .catch((err: any) => {
      loadingSync.value = false;
      VxeMessage('同步失败', VxeNotifyType.error);
    });
}
async function pullItemDictKnowLedge() {
  showKnowLedgeLoading.value = true;
  const url = '/api/sys/hisEmployee/getInterfaceData';
  const params = {
    url: '/dictItemKnowledge/syncDictItemKnowledge',
    code: 'SYNC_DICT_ITEM_KNOWLEDGE'
  };
  proxy.$http
    .get(url, { params: params })
    .then((res: any) => {
      VxeMessage('同步成功', VxeNotifyType.success);
      showKnowLedgeLoading.value = false;
      getReportItemList();
    })
    .catch((err: any) => {
      showKnowLedgeLoading.value = false;
      VxeMessage('同步失败', VxeNotifyType.error);
    });
}

//上移
function moveUp() {
  const item1 = itemList[sltItemIndex.value];
  const item2 = itemList[sltItemIndex.value - 1];

  const up1 = {
    id: item1.id,
    seq: item2.seq
  };
  const up2 = {
    id: item2.id,
    seq: item1.seq
  };
  const upList: any = [];
  upList.push(up1);
  upList.push(up2);
  updateMoveSeq(upList);
}
//下移
function moveDown() {
  const item1 = itemList[sltItemIndex.value];
  const item2 = itemList[sltItemIndex.value + 1];

  const up1 = {
    id: item1.id,
    seq: item2.seq
  };
  const up2 = {
    id: item2.id,
    seq: item1.seq
  };
  const upList: any = [];
  upList.push(up1);
  upList.push(up2);
  updateMoveSeq(upList);
}

function updateMoveSeq(upList: any) {
  const url = '/lis/lab/item/updateMoveItemDictSeq';
  const data = { labItemDictList: upList };
  proxy.$http
    .post(url, data)
    .then((res: any) => {
      findLabItemDictList();
      VxeMessage(res.status.msg, VxeNotifyType.success);
    })
    .catch((err: any) => {
      proxy.$alert(err, '提示');
    });
}
function searchWklt(propValue: any,name: any,workGroup: any,workGroupName : any) {
  searchMenuForm.workGroup=workGroup.value;
  GetRptGroupOptions(propValue.value);
  searchForm.rptGroup = propValue.value;
  searchForm.workGroup = workGroup.value;
  searchForm.workGroupName = workGroupName.value;
  getReportItemList();
}
function getWorkGroupName(row) {
  // proxy.$nextTick(() => {
  if (workGroupList.length > 0) {
    const group = workGroupList.find((item) => item.code == row.workGroup);
    return group ? group.name : '';
  }
}

</script>
<style lang="scss" scoped>
#labItemDict {
  width: 100%;
  height: 100%;

  .bodyContent {
    height: calc(100% - 60px);

    .splitpanes {
      background-color: $base-white;

      .el-tabs {
        height: 100%;

        :deep(.el-tabs__content) {
          height: calc(100% - 40px);
          padding: 0 10px;

          .el-tab-pane {
            height: 100%;
          }
        }
      }
    }
    .tableBody {
      height: calc(100%);
    }

    .searchform {
      padding: 10px 0 0 10px;

      :deep(.vxe-form--item) {
        margin-right: 30px;
      }
    }

    .searchform .vxe-input {
      --el-input-width: 120px;
    }

    .searchform .vxe-select {
      --el-select-width: 120px;
    }

    // 附加按钮间距
    .button-blue,
    .button-red {
      margin: 5px 0 5px 5px;
    }
  }
}
</style>
